package com.test;


/*
// 定义类MaxPriority实现Runnable接口
class MaxPriority implements Runnable {
    public void run() {
        for(int i = 0; i <5;i++){
            System.out.println(Thread.currentThread().getName()+"正在输出:"+i);
        }
    }
}

class MinPriority implements Runnable {
    public void run() {
        for(int i = 0; i <5;i++){
            System.out.println(Thread.currentThread().getName()+"正在输出:"+i);
        }
    }
}

public class Example03 {
    public static void main(String[] args) {
        Thread minPriority =new Thread(new MinPriority(),"优先级较低的线程");
        Thread maxPriority =new Thread(new MaxPriority(),"优先级较高的线程");
        minPriority.setPriority(Thread.MIN_PRIORITY); //设置线程的优先级1
        maxPriority.setPriority(Thread.MAX_PRIORITY); //设置线程的优先级10
        //开启两个线程
        maxPriority.start();
        minPriority.start();
    }
}

 */


// 定义SleepThread类实现Runnable接口
class SleepThread implements Runnable {
    public void run() {
        for (int i = 1; i <= 8; i++) {
            if (i == 3) {
                try {
                    Thread.sleep(2000); // 当前线程休眠2秒
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("SleepThread线程正在输出:" + i);
            try {
                Thread.sleep(500); // 当前线程休眠500毫秒
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

public class Example03 {
    public static void main(String[] args) throws Exception {
        // 创建一个线程
        new Thread(new SleepThread()).start();
        for (int i = 1; i <= 8; i++) {
            if (i == 5) {
                Thread.sleep(2000);  // 当前线程休眠2000毫秒
            }
            System.out.println("主线程正在输出:" + i);
            Thread.sleep(500); // 当前线程休眠500毫秒
        }
    }
}